package com.yayan.beautyclub.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yayan.beautyclub.bean.Keep;
import com.yayan.beautyclub.service.IKeepService;

@Controller
@RequestMapping(value="/keep", method=RequestMethod.POST)
public class KeepController {

	@Autowired
	private IKeepService keepService;
	
	@RequestMapping(value="/keep_list.do")
	@ResponseBody
	public List<Map<String, Object>> getKeepList(@RequestBody Map<String, String> map){
		long uId = Long.parseLong(map.get("uId"));
		int page = Integer.parseInt(map.get("page"));
		int size = Integer.parseInt(map.get("size"));
		return keepService.getKeepByUserId(uId, page, size);
	}
	
	@RequestMapping(value="/create.do")
	@ResponseBody
	public boolean createKeep(@RequestBody Keep keep){
		long kId = keepService.saveKeep(keep);
		if(kId == 0L)
			return false;
		return true;
	}
	
	@RequestMapping(value="/get_keep.do")
	@ResponseBody
	public Map<String, Object> getKeep(@RequestBody Map<String, String> map){
		long kId = Long.parseLong(map.get("kId"));
		return keepService.getKeepByKeepId(kId);
	}
	
	@RequestMapping(value="/delete_keep.do")
	@ResponseBody
	public boolean deleteKeep(@RequestBody Map<String, String> map){
		long kId = Long.parseLong(map.get("kId"));
		return keepService.deleteKeep(kId);
	}
}
